<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录页面</title>
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
</head>
<body>
<form action="/login1" method="post" enctype="application/x-www-form-urlencoded">
    用户名:<input type="text" name="name" id="name" value="admin"> <br>
    密码：<input type="text" name="password"  id="password" value="admin"> <br>
  <input type="submit" value="提交"><br><br>
    <input type="button" value="Ajax提交" id="btn_submit">
    <div style="color: orangered;" id="show_msg">${msg}</div>
</form>
</body>
</html>
<script>
    $(function () {
       //获取按钮的节点
        $("#btn_submit").click(function () {
            var name = $("#name").val().trim();
            var password = $("#password").val().trim();
            $.ajax({
                type: "POST",
                url: "/login2",
                contentType:"application/json",
                //把 javascript 对象转成字符串
                data:JSON.stringify({"name":name,"password":password}) ,
                success: function(data){
                   if(data["success"]){
                       //浏览再次跳转的页面
                        window.location.href="http://www.qq.com";//// "/page/success";
                   }else{
                       // console.info(data["msg"]);
                       $("#show_msg").html(data["msg"]);
                   }
                },
                dataType:"json"
            });
        });
    })
</script>
